home *** CD-ROM | disk | FTP | other *** search
- /******************************************************************
- * NOS.C
- *
- * Program extracting IP-address from the STIK config file:
- * C:\STIK_CFG\CONFIG.SAV
- *
- * Then posts it into 'STARTUP.NOS'
- *
- * The program is named 'NOS.TTP' to trick 'OASIS' to fork
- * this one instead of the actual 'NOS.TTP'.
- * This program forks the real 'NOS' which has to be renamed
- * to 'NOSEXT.TTP'.
- *
- * ----------------------------------------------------------
- * 1995-12-31 Relative pathways used instead of absolute
- *
- *******************************************************************/
-
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
-
- #define TRUE 1
- #define FALSE 0
-
- void main(argc, argv)
- int argc;
- char *argv[];
- {
- FILE *fp; /* file pointer */
-
- long buf; /* buffer */
-
- char IP[50]; /* IP-address string */
-
- static char line[200][100]; /* input text line from file */
-
- short fld1, fld2, fld3, fld4,
- i, j,
- insert;
-
-
-
-
- /* get IP from 'STIK' config file */
- if ((fp = fopen("C:\\STIK_CFG\\CONFIG.SAV", "rb")) == NULL) {
- exit(0);
- }
- fread(&buf, sizeof(long), 1, fp);
- fclose(fp);
- if ((fp = fopen("C:\\STIK_CFG\\CONFIG.SAV", "rb")) == NULL) {
- exit(0);
- }
- fread(&buf, sizeof(long), 1, fp);
- fclose(fp);
-
- /* extract IP address byte fields */
- fld1 = buf & 0xFF;
- fld2 = (buf >> 8) & 0xFF;
- fld3 = (buf >> 16) & 0xFF;
- fld4 = (buf >> 24) & 0xFF;
-
- /* build IP address string */
- sprintf(IP, "ip addr [%d.%d.%d.%d]\n", fld4, fld3, fld2, fld1);
-
-
- if ((fp = fopen("STARTUP.NOS", "r+")) == NULL) {
- printf("Failed to open \"STARTUP.NOS\"\n");
- exit(0);
- }
-
- insert = FALSE;
- for (i = 0; i < 200; i++) {
- if ((fgets(line[i], 100, fp)) == NULL) {
- break;
- }
- if (!strncmp(line[i], "ip addr ", 8)) {
- strcpy(line[i], IP);
- }
- }
-
- fclose(fp);
-
- if ((fp = fopen("STARTUP.NOS", "w")) == NULL) {
- printf("Failed to open \"STARTUP.NOS\"\n");
- exit(0);
- }
-
- j = 0;
- for (; i >= 0; --i) {
- fputs(line[j++], fp);
- }
-
- fclose(fp);
-
- strcpy(argv[0], "NOSEXT.TTP");
- forkv(argv[0], argv);
-
- exit(0);
- }
-